'use strict';
const db = uniCloud.database()
const dbCmd = db.command
exports.main = async (event, context) => {




	if (event.sign == 1) { //初始化成员状态
		const coll = db.collection('user')
		let res = await coll.where({
			biaoshi: 'biaoshi'
		}).update({
			status: 0,
			seat: '',
			jifen: 0,
			pic: '',
			bianshou: false
		})
		return res
	} else if (event.sign == 2) {
		const coll1 = db.collection('chuangxin')
		const coll2 = db.collection('tuandui')
		const coll3 = db.collection('zhuanye')
		const coll4 = db.collection('zhunru')
		let res1 = await coll1.where({
			biaoshi: 'biaoshi'
		}).update({
			Status: 0,
			suoding: '',
			userID: ''
		})
		let res2 = await coll2.where({
			biaoshi: 'biaoshi'
		}).update({
			Status: 0,
			suoding: '',
			userID: ''
		})
		let res3 = await coll3.where({
			biaoshi: 'biaoshi'
		}).update({
			Status: 0,
			suoding: '',
			userID: ''
		})
		let res4 = await coll4.where({
			biaoshi: 'biaoshi'
		}).update({
			Status: 0,
			suoding: '',
			userID: ''
		})



		let res
		res = Object.assign(res1, res2, res3, res4)
		return res
	} else if (event.sign == 3) { //注册
		const coll = db.collection('seat-user')
		let res = await coll.where({
			username: event.username,
			wwid: event.wwid
		}).limit(1).count()
		if (res.total) {
			return {
				msg: '该账号已存在'
			}
		} else {
			let res1 = await coll.add({
				"biaoshi": "biaoshi",
				"group": "none",
				"seat": [],
				"status": 0,
				"username": event.username,
				"wwid": event.wwid
			})
			return res1
		}

	} else {
		return '暂无操作'
	}

};
